import requests
import json

# 1.基础请求

# url = 'http://httpbin.org/get?name=zzf'
#
# respons = requests.get(url,params={'age':19})
#
# if respons.status_code == 200:
#     # 初级
#     respons_bytes = respons.content
#     print(respons_bytes)
#     respons_str = respons_bytes.decode('utf-8')
#     respons_json = json.loads(respons_str)
#     print(respons_json)
#
#     # 中级 text 得到的是urlencode字符串需要  json.loads进行序列化为字典类型
#     respons_str = respons.text
#     respons_json = json.loads(respons_str)
#     print(respons_json,type(respons_json))
#
#
#     # 高级json 可以的到json格式  将字典类型的字符串转换为字典格式
#     respons_json = respons.json()
#     print(respons_json)




# # 2.使用默认请求参数的类型 'Content-Type': 'application/x-www-form-urlencoded'
# url = 'http://httpbin.org/post?name=zzf'
#
# respons = requests.post(url,data={'sex':'男'})
#
# if respons.status_code == 200:
#     # 高级json 可以的到json格式  将字典类型的字符串转换为字典格式
#     respons_json = respons.json()
#     print(respons_json)
#     print(respons.request.headers)


# # 3.使用json请求参数的类型 'Content-Type': 'application/json'
# url = 'http://httpbin.org/post?name=zzf'
#
# respons = requests.post(url,json={'sex':'男'},headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36'})
#
# if respons.status_code == 200:
#     # 高级json 可以的到json格式  将字典类型的字符串转换为字典格式
#     respons_json = respons.json()
#     print(respons_json)
#     print(respons.request.headers)


# # 4.图片类型的二进制字节流要用content
# url= 'http://www.henan100.com/d/file/bdnews/20251027/3d7643d5caaed3c4761692e3c269cf70.jpg'
# response = requests.get(url)
#
# with open("tu/tuu.jpg","wb") as f:
#     f.write(response.content)
# print(response.content)